package text111;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class Solution25 {
	public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode res = new ListNode(0), cur = res;
		ArrayList<Integer> arrayList = new ArrayList<Integer>();
	//	LinkedList<Integer> linkedList = new LinkedList<Integer>();
		
		while(l1!=null) {
			arrayList.add(l1.val);
			l1 = l1.next;
		}
		while(l2!=null) {
			arrayList.add(l2.val);
			l2 = l2.next;
		}
       int[]list = new int[arrayList.size()];
		for (int i = 0; i < arrayList.size(); i++) {
			list[i] = arrayList.get(i);	
		}
       for (int i = 0; i < list.length; i++) {
			System.out.println(list[i]);
		}
		Arrays.sort(list);
        for (int i = 0; i < list.length; i++) {
			System.out.print(list[i]);
		}       
      // System.out.println(list);
			for (int i = 0; i < list.length; i++) {
				ListNode tmpNode = new ListNode(list[i]);
             //  System.out.println(res);
				if (res.next==null) { 
              //     System.out.println("a");
					res.next = tmpNode;		
                   System.out.println(res.next);		
					res =res.next; }
				 
			//	add(res, list[i]);
			}
		
		return cur.next;
	    }
	/*
	 * public void add(ListNode lNode,int newval) { lNode = new ListNode(newval);
	 * if(lNode.next == null) lNode.next = lNode; else lNode.val=newval; }
	 */
}
